﻿using System;
using System.Collections.Generic;
using System.Text;

namespace IOP.OpenType
{
    /// <summary>
    /// CFF操作数
    /// </summary>
    public struct CFFOperand
    {
        /// <summary>
        /// 值
        /// </summary>
        public double Value;
        /// <summary>
        /// 类型
        /// </summary>
        public OperandKind Kind;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="value"></param>
        public CFFOperand(int value)
        {
            Value = value;
            Kind = OperandKind.IntNumber;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="value"></param>
        public CFFOperand(double value)
        {
            Value = value;
            Kind = OperandKind.RealNumber;
        }
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="b"></param>
        public static implicit operator CFFOperand(byte b) => new CFFOperand(b);
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="u"></param>
        public static implicit operator CFFOperand(ushort u) => new CFFOperand(u);
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="s"></param>
        public static implicit operator CFFOperand(short s) => new CFFOperand(s);
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="i"></param>
        public static implicit operator CFFOperand(int i) => new CFFOperand(i);
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="u"></param>
        public static implicit operator CFFOperand(uint u) => new CFFOperand((int)u);
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="f"></param>
        public static implicit operator CFFOperand(float f) => new CFFOperand(f);
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="d"></param>
        public static implicit operator CFFOperand(double d) => new CFFOperand(d);
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="operand"></param>
        public static implicit operator int(CFFOperand operand) => (int)operand.Value;
        /// <summary>
        /// 隐式转换
        /// </summary>
        /// <param name="operand"></param>
        public static implicit operator float(CFFOperand operand) => (float)operand.Value;

        public static implicit operator double(CFFOperand operand) => operand.Value;
    }

    /// <summary>
    /// 操作数类型
    /// </summary>
    public enum OperandKind
    {
        /// <summary>
        /// 整数
        /// </summary>
        IntNumber,
        /// <summary>
        /// 实数
        /// </summary>
        RealNumber
    }
}
